var interval_id;
var animando_interior = false;
var email_title = "feedback";

$(document).ready(function(){
  $(".contact").click(function(){
    $("#email").focus();
    $("#feedback_form h2").text("Say Hello");
    $("#feedback_form #subject").val("Hello.")
    $("#feedback_form").fadeIn();
  });

  $("#header h1").click(function(){
    document.location = "/";
  });

  $(".close_form").click(function(){
    $("#feedback_form").fadeOut();
  });

  $(".join_us").click(function(){
    $("#feedback_form h2").text("Join us");
    $("#feedback_form #subject").val("I want to join narwhalware.")
    $("#feedback_form").fadeIn();
  });

  $(".feedback").click(function(){
    $("#feedback_form h2").text("What do you think?");
    $("#feedback_form #subject").val("This is what I think.")
    $("#feedback_form").fadeIn();
  });

  $(".troubleshooting").click(function(){
    $("#feedback_form h2").text("Troubleshooting");
    $("#feedback_form #subject").val("I need help with something.")
    $("#feedback_form").fadeIn();
  });


  $("#btnSend").click(function(){
    var params = {title: email_title,
                  email: $("#email").val(),
                  subject: $("#subject").val(),
                  feedback: $("#feedback").val()
    };
    $.post("/process_form.php",params,function(data){
    });
    email_title = "feedback";
    $("input, textarea").val("");
    $("#feedback_form").hide();
  });

  $("#left-slider").click(function(){
    clearInterval(interval_id);
    if(!animando_interior)
      animateLeft();
  });
  
  $("#right-slider").click(function(){
    clearInterval(interval_id);
    if(!animando_interior)
      animateRight();
  });
  interval_id = setInterval(animateRight,15000);
  animateInternal();
});

function animateRight(){
  var elem = $("#sub-slider");

  if(elem.position().left == 0){
      $("#slice-b .slice-anim-a,#slice-b .slice-anim-b,#slice-b .slice-anim-c").css({left:"-470px"});
      elem.animate({left: -880}, { duration: 500});
      setTimeout(function(){animateInternal()},700);
    }
    if(elem.position().left == -880){
      $("#slice-c .slice-anim-a,#slice-c .slice-anim-b,#slice-c .slice-anim-c").css({left:"-470px"});
      elem.animate({left: -1760}, { duration: 500});
      setTimeout(function(){animateInternal()},700);
    }
    if(elem.position().left == -1760){
      $("#slice-a .slice-anim-a,#slice-a .slice-anim-b,#slice-a .slice-anim-c").css({left:"-470px"});
      elem.animate({left: 0}, { duration: 500});
      setTimeout(function(){animateInternal()},700);
    }
}

function animateLeft(){
  var elem = $("#sub-slider");

  if(elem.position().left == 0){
    $("#slice-c .slice-anim-a,#slice-c .slice-anim-b,#slice-c .slice-anim-c").css({left:"-470px"});
    elem.animate({left: -1760}, { duration: 500});
      setTimeout(function(){animateInternal()},700);
    }
    if(elem.position().left == -880){
      $("#slice-a .slice-anim-a,#slice-a .slice-anim-b,#slice-a .slice-anim-c").css({left:"-470px"});
      elem.animate({left: 0}, { duration: 500});
      setTimeout(function(){animateInternal()},700);
    }
    if(elem.position().left == -1760){
      $("#slice-b .slice-anim-a,#slice-b .slice-anim-b,#slice-b .slice-anim-c").css({left:"-470px"});
      elem.animate({left: -880}, { duration: 500});
      setTimeout(function(){animateInternal()},700);
    }
}

function animateInternal(){
  animando_interior = true;
  $(".slice-anim-a").delay(300).animate({left:6}, { duration: 400});
  $(".slice-anim-b").delay(150).animate({left:431}, { duration: 700});
  $(".slice-anim-c").delay(50).animate({left:654}, 400,function(){
      animando_interior = false;
  });

  
}



